Object.defineProperty(exports, "__esModule", {
  value: true
});
var PlayerDataManager = require("AA_PlayerDataManager");
var Excel = require("AA_Excel");
var GameDataManager = require("AA_GameDataManager");
var NodePoolMag = require("AA_NodePoolMag");
var BundleConfig = require("AA_BundleConfig");
var AudioManager = require("AA_AudioManager");
var LogManager = require("AA_LogManager");
var TipsManager = require("AA_TipsManager");
var ResLoader = require("AA_ResLoader");
var _def_CommonUtils = function () {
  function _creator() {}
  _creator.limit = function (e, t) {
    e = Math.min(e, t);
    var o = (t = Math.max(e, t)) - e;
    return e + Math.random() * o;
  };
  _creator.limitInteger = function (e, t) {
    return Math.floor(this.limit(e, t + 1));
  };
  _creator.getRandomInt = function (e, t) {
    var o;
    if (e > t) {
      e = (o = [t, e])[0];
      t = o[1];
    }
    return Math.floor(Math.random() * (t - e + 1)) + e;
  };
  _creator.LimitSpriteMaxSize = function (e, t) {
    if (e.spriteFrame) {
      var o = e.spriteFrame.getOriginalSize();
      if (o.width > t || o.height > t) {
        var n = o.width > o.height ? t / o.width : t / o.height;
        n = n > 1 ? 1 : n;
        return void (e.node.scale = n);
      }
    }
    e.node.scale = 1;
  };
  _creator.pointInRect = function (e, t) {
    var o = t.x - t.width / 2;
    var n = t.x + t.width / 2;
    var i = t.y - t.height / 2;
    var a = t.x + t.height / 2;
    return e.x > o && e.x < n && e.y > i && e.y < a;
  };
  _creator.onshare = function (e) {
    if (window.tt) {
      mg.shareAppMessage({
        success: function () {
          e(true);
        }
      });
    } else {
      window.wx && this.wxshare(e);
    }
  };
  _creator.wxshare = function (e) {
    var t = this;
    if (window.wx) {
      window.wx.onShow(function o() {
        window.wx.offShow(o);
        Date.now();
        t._lastShareTime;
        if (e) {
          if (t.failcount < 2) {
            if (Date.now() - t._lastShareTime > 2e3) {
              if (Math.random() < .3) {
                e(false);
                TipsManager.TipMgr.showToast("分享失败,请分享至群聊");
                t.failcount++;
              } else {
                TipsManager.TipMgr.showToast("分享成功");
                e(true);
              }
            } else {
              t.failcount++;
              e(false);
              TipsManager.TipMgr.showToast("分享失败,请重新分享");
            }
          } else {
            TipsManager.TipMgr.showToast("分享成功");
            t.failcount = 0;
            e(true);
          }
        }
      });
      this._lastShareTime = Date.now();
      window.wx.shareAppMessage({
        imageUrlId: "L1Vd19CmR3i/aikD7oi6AA==",
        imageUrl: "https://mmocgame.qpic.cn/wechatgame/HzPjqjMkXIeKHvHlQpQlOIhqrT16YcNugEZFHaeSnY0iaubd26dKyiaQtkVeXRyLTU/0",
        title: "吃不到我呀"
      });
    }
  };
  _creator.replaceSymbols = function (e, t, o) {
    var n = e;
    for (var i = 0; i < o.length; i++) {
      n = n.replace(t, o[i] + "");
    }
    return n;
  };
  _creator.showCoin = function (e, t, o, n, r, c) {
    undefined === r && (r = true);
    undefined === c && (c = null);
    return __awaiter(this, undefined, undefined, function () {
      var i;
      var s;
      return __generator(this, function (a) {
        switch (a.label) {
          case 0:
            i = NodePoolMag.NodePoolMag.instance.getNode("coin");
            AudioManager.AudioMgr.playEffect("audio/effect/daozhang", false);
            if (i) {
              return [3, 2];
            } else {
              return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Common, "common/prefab/CoinIcon", cc.Prefab)];
            }
          case 1:
            s = a.sent();
            NodePoolMag.NodePoolMag.instance.createNodeCount("coin", 1, s, null);
            if (t) {
              this.playGold({
                toP: e,
                count: 10,
                num: o,
                name: n,
                inP: t,
                issave: r,
                feiover: c
              });
            } else {
              this.playGold({
                toP: e,
                count: 10,
                num: o,
                name: n,
                issave: r,
                feiover: c
              });
            }
            return [3, 3];
          case 2:
            if (t) {
              this.playGold({
                toP: e,
                count: 10,
                num: o,
                name: n,
                inP: t,
                issave: r,
                feiover: c
              });
            } else {
              this.playGold({
                toP: e,
                count: 10,
                num: o,
                name: n,
                issave: r,
                feiover: c
              });
            }
            a.label = 3;
          case 3:
            return [2];
        }
      });
    });
  };
  _creator.cleanGold = function () {
    return __awaiter(this, undefined, undefined, function () {
      return __generator(this, function () {
        cc.director.getScene().children.forEach(function (e) {
          "fei_yinbi" == e.name && NodePoolMag.NodePoolMag.instance.recycleNode("coin", e);
        });
        return [2];
      });
    });
  };
  _creator.playGold = function (t) {
    return __awaiter(this, undefined, undefined, function () {
      var o;
      var n;
      var i;
      var c;
      var d;
      return __generator(this, function (p) {
        switch (p.label) {
          case 0:
            o = function (e) {
              return Math.floor(Math.random() * e);
            };
            n = {
              inP: cc.v2(cc.winSize.width / 2, cc.winSize.height / 2),
              toP: cc.v2(-320, 600),
              count: 6,
              num: 0,
              name: "gold",
              issave: true,
              feiover: null
            };
            Object.assign(n, t);
            if (t.issave) {
              switch (t.name) {
                case "yinbi":
                  GameDataManager.GameDataMgr.AddSliderCoin(n.num);
                  break;
                case "power":
                  PlayerDataManager.PlayerDataMgr.AddPower(n.num);
                  break;
                case "jinbi":
                  PlayerDataManager.PlayerDataMgr.AddGold(n.num);
                  break;
                case "zuanshi":
                  PlayerDataManager.PlayerDataMgr.AddDiamond(n.num);
              }
            }
            i = function (e) {
              var i;
              var r;
              var c;
              var s;
              var d;
              var p;
              return __generator(this, function (a) {
                switch (a.label) {
                  case 0:
                    if (!(i = NodePoolMag.NodePoolMag.instance.getNode("coin"))) {
                      return [2, {
                        value: undefined
                      }];
                    }
                    r = i.getChildByName("img").getComponent(cc.Sprite);
                    c = null;
                    switch (t.name) {
                      case "yinbi":
                        return [3, 1];
                      case "jinbi":
                        return [3, 3];
                      case "zuanshi":
                        return [3, 5];
                      case "power":
                        return [3, 7];
                    }
                    return [3, 9];
                  case 1:
                    return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Game, "game/res/yinbi", cc.SpriteFrame)];
                  case 2:
                    c = a.sent();
                    return [3, 9];
                  case 3:
                    return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Common, "common/res/ui/tu/goldIcon", cc.SpriteFrame)];
                  case 4:
                    c = a.sent();
                    return [3, 9];
                  case 5:
                    return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Common, "common/res/ui/tu/diamondIcon", cc.SpriteFrame)];
                  case 6:
                    c = a.sent();
                    return [3, 9];
                  case 7:
                    return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Common, "common/res/ui/tu/powerIcon", cc.SpriteFrame)];
                  case 8:
                    c = a.sent();
                    return [3, 9];
                  case 9:
                    i.name = "fei_yinbi";
                    r.spriteFrame = c;
                    i.zIndex = cc.macro.MAX_ZINDEX;
                    i.setPosition(n.inP);
                    cc.director.getScene().addChild(i);
                    s = o(240) - 120;
                    d = o(240) - 120;
                    p = o(200) / 1e3;
                    cc.tween(i).delay(p).by(.6, {
                      x: s,
                      y: d
                    }, {
                      easing: cc.easing.quadOut
                    }).to(1, {
                      x: n.toP.x,
                      y: n.toP.y
                    }, {
                      easing: cc.easing.quartIn
                    }).call(function () {
                      if (0 != e) {
                        return NodePoolMag.NodePoolMag.instance.recycleNode("coin", i);
                      }
                      t.feiover && t.feiover();
                      NodePoolMag.NodePoolMag.instance.recycleNode("coin", i);
                    }).start();
                    return [2];
                }
              });
            };
            c = 0;
            p.label = 1;
          case 1:
            if (c < n.count) {
              return [5, i(c)];
            } else {
              return [3, 4];
            }
          case 2:
            if ("object" == typeof (d = p.sent())) {
              return [2, d.value];
            }
            p.label = 3;
          case 3:
            c++;
            return [3, 1];
          case 4:
            return [2];
        }
      });
    });
  };
  _creator.ChildrenLayout = function (e, t, o) {
    undefined === t && (t = 0);
    undefined === o && (o = true);
    var n = e.children;
    var i = [];
    if (n.length <= 1) {
      if (1 == n.length) {
        i.push(cc.Vec2.ZERO);
        o && e.children[0].setPosition(0, 0);
      }
      return i;
    }
    var a = 0;
    n.forEach(function (e) {
      return a += e.width;
    });
    a += (n.length - 1) * t;
    var r = 0;
    for (var c = -1; c < n.length - 1; c++) {
      r += -1 == c ? a / 2 * -1 + n[0].width / 2 : n[c].width / 2 + t + n[c + 1].width / 2;
      i.push(cc.v2(r, 0));
      o && (n[c + 1].x = r);
    }
    return i;
  };
  _creator.SendPoint = function (e, t) {
    this.sendPointDataByItemName(e, t);
    LogManager.LogMgr.debug("发送埋点", e, t);
  };
  _creator.sendPointDataByItemName = function (e, t) {
    var o;
    var n = t;
    if (n) {
      var i = undefined;
      if (window.tt) {
        i = window.tt;
      } else {
        window.wx && (i = window.wx);
      }
      i && i.uma && (null === (o = i.uma) || undefined === o || o.trackEvent(e, {
        itemName: n
      }));
    }
  };
  _creator.LoadLevel5Effect = function (e, t, o, n, r, c) {
    undefined === r && (r = null);
    undefined === c && (c = null);
    return __awaiter(this, undefined, undefined, function () {
      return __generator(this, function () {
        t && t.destroyAllChildren();
        n(BundleConfig.BundleNames.Common, "common/"+"item/item_level5_qi_" + e, cc.Prefab).then(function (e) {
          var o = cc.instantiate(e);
          if (t) {
            o.parent = t;
            o.setPosition(0, 0);
          }
          r && r(o);
        });
        o && o.destroyAllChildren();
        n(BundleConfig.BundleNames.Common, "common/"+"item/item_level5_huo_" + e, cc.Prefab).then(function (e) {
          var t = cc.instantiate(e);
          if (o) {
            t.parent = o;
            t.setPosition(0, 0);
          }
          c && c(t);
        });
        return [2];
      });
    });
  };
  _creator.getPointAngle = function (e, t) {
    var o = t.x - e.x;
    var n = t.y - e.y;
    return -cc.v2(o, n).signAngle(cc.v2(1, 0)) / Math.PI * 180;
  };
  _creator.getNewGongGao = function () {
    var e = this;
    var t = Excel.Excel.shuiguogonggao_all;
    if (!t) {
      return [];
    }
    var o = t.size;
    var n = [];
    for (var i = 0; i < o; i++) {
      var a = t.get(i + 1);
      this.getServerTime(a.time);
      new Date().getTime();
      1 == a.isshow && n.push(a);
    }
    n.sort(function (t, o) {
      if (e.getServerTime(t.time) > e.getServerTime(o.time)) {
        return -1;
      } else {
        return 1;
      }
    });
    return n;
  };
  _creator.getServerTime = function (e) {
    return new Date(e).getTime();
  };
  _creator._onShow = null;
  _creator._lastShareTime = 0;
  _creator.failcount = 0;
  return _creator;
}();
exports.default = _def_CommonUtils;